package com.shoe.service.impl;

import com.shoe.mapper.ShoeCartMapper;
import com.shoe.pojo.Cart;
import com.shoe.pojo.ShoeCart;
import com.shoe.pojo.ShoeCartExample;
import com.shoe.service.ShoeCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class ShoeCartServiceImpl implements ShoeCartService {
    @Autowired
    ShoeCartMapper shoeCartMapper;

    @Override
    public List<Cart> selectAll(Integer cartUserId) {
        return shoeCartMapper.selectAll(cartUserId);
    }

    @Override
    public int deleteById(Long cartId) {
        return shoeCartMapper.deleteByPrimaryKey(cartId);
    }

    @Override
    public int addCart(Long userId, Long goodId , Integer goodMoney , Integer goodSize) {
        System.out.println(userId);
        ShoeCart shoeCart = new ShoeCart();
        Short a =1;
        shoeCart.setCartGoodNum(a);
        shoeCart.setCartGoodId(goodId);
        shoeCart.setCartUserId(userId);
        shoeCart.setCartGoodSubmon(goodMoney);
        shoeCart.setCartGoodSize(goodSize);
        return shoeCartMapper.insert(shoeCart);
    }

    @Override
    public int selectId(Long userId,Long goodId ) {

        ShoeCartExample shoeCartExample = new ShoeCartExample();
        shoeCartExample.createCriteria().andCartGoodIdEqualTo(goodId).andCartUserIdEqualTo(userId);
        List<ShoeCart> list = shoeCartMapper.selectByExample(shoeCartExample);
        System.out.println(list.size());
        if(list != null && list.size() > 0){
            return 1;
        }
        return 0;
    }


}

